/**
 * 处理子组件对象
 * MVVM Component
 * @className: Component
 * version: 0.0.1
 * nextUpdate: NaN
 * updateTime: 2021/06/03
 * @Author 洛水天依 <luotianyiovo@gmail.com>
 */
class Component {
    // List<VNode> vnode = []
    vNode = []
    // 数据对象
    data = []
    // 父节点
    parent = {}
    dom = HTMLElement
    owningNode = {}

    options = {}

    /**
     * @param vNode 当前节点对象
     * @param parent 父节点对象
     * @param dom 本dom 节点对象
     */
    constructor(vNode, parent, dom) {
        this.vNode = vNode.vNode
        this.parent = parent
        this.owningNode = vNode
        this.dom = dom
        this.options = vNode.options
    }

    setData(data) {
        this.data = Object.assign({}, data)
        return this
    }

    // 设置PropsData
    setProps(data, owData) {
        // 解析Tag Props属性
        for (let index = 0; index < this.dom.attributes.length; index++) {
            let attr = this.dom.attributes[index]
            if (attr.nodeName.startsWith("props-")) {
                let attrsProps = attr.nodeName.split('-')[1]
                this.owningNode.props[attrsProps] = (
                    getObjectValue(data, attr.nodeValue) || getObjectValue(owData, attr.nodeValue)
                ) || attr.nodeValue
            }
        }
        return this
    }

    getDomElement() {
        return new VNode('div').traverseVNodeCreatDom(
            this.vNode, Object.assign(this.data, this.owningNode.props)
        )
    }
}